<?php 
require_once(dirname(dirname(__FILE__)) . '/app.php');

check_login();

$action = strval($_GET['action']);
$id = abs(intval($_GET['id']));
$refurl = strval($_GET['refurl']);

if ($action == 'change') {
	
	if ($id) {
		
		$up_sql = "update address set `default` = 'N' where user_id = {$login_user_id}";
		DB::Query($up_sql);
		
		$rs = $up_sql = "update address set `default` = 'Y' where user_id = {$login_user_id} and id ={$id}";
		DB::Query($up_sql);
		
		$result = array('has_ref'=>false);
		
		if(!empty($refurl))
		{
			$result['has_ref'] = true;
			$result['refurl'] = $refurl.'&aid='.$id;
		}
		echo json_encode($result);
		die();
	}
	
}
?>